package com.example.administrator.x3picturetransliteration.Home.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.example.administrator.x3picturetransliteration.R;

/**
 * 支付
 * Created by Administrator on 2019/8/27.
 */

public class PaymentDialog extends Dialog{

    private hd mhd;

    private ImageView zfbImg;
    private ImageView wxImg;

    private boolean judge = true;

    public PaymentDialog(@NonNull Context context,hd mhd) {
        super(context, R.style.HomeDialog);

        this.mhd = mhd;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_dialog_payment);

        zfbImg = findViewById(R.id.zfbImg);
        wxImg = findViewById(R.id.wxImg);

        findViewById(R.id.zfbView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                judge = true;
                style();
            }
        });

        findViewById(R.id.wxView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                judge = false;
                style();
            }
        });

        findViewById(R.id.endView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                PaymentDialog.this.dismiss();
            }
        });

        /** 支付 */
        findViewById(R.id.zfText).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mhd.hdff(judge);
                PaymentDialog.this.dismiss();
            }
        });

    }

    private void style(){

        if (judge){

            zfbImg.setImageResource(R.mipmap.home_check);
            wxImg.setImageResource(R.mipmap.home_uncheck);
        }else {

            zfbImg.setImageResource(R.mipmap.home_uncheck);
            wxImg.setImageResource(R.mipmap.home_check);
        }

    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity= Gravity.BOTTOM;
        layoutParams.width= WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height= WindowManager.LayoutParams.WRAP_CONTENT;

        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);

    }

    public interface hd{

        void hdff(boolean judge);
    }

}
